package com.wk.lib_base.net

import retrofit2.Retrofit

object RetrofitUtil {

    private lateinit var INSTANCE: Retrofit
    private var needRegetIns = false //有时候调整了参数，需要重新build一下retrofit

    private var baseUrl = "https://wanandroid.com/"

    fun ins(otherBaseUrl: String = baseUrl): Retrofit {
        if (!this::INSTANCE.isInitialized || needRegetIns || (otherBaseUrl.isNotEmpty() && otherBaseUrl != baseUrl)) {
            if (otherBaseUrl.isNotEmpty()) {
                baseUrl = otherBaseUrl
            }
            INSTANCE = Retrofit.Builder()
                .baseUrl(baseUrl)
                .client(OkhttpClientUtil.clientIns())
                .addConverterFactory(Retrofit2ConverterFactory())
//                .addConverterFactory(MoshiConverterFactory.create())
                .build()
        }
        return INSTANCE
    }


}
